package com.hqyj.onlineExamination.modules.account.controller;

import com.hqyj.onlineExamination.modules.account.service.UserService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class AccountController {

    @Autowired
    private UserService userService;

    /**
     * 前端首页。
     */
    @GetMapping("/front/index")
    public String frontIndex(){
        return "front/index";
    }

    /**
     * 前端首页中的轮播图。
     */
    @GetMapping("/front/index-2")
    public String frontIndex2( ){
        return "front/index";
    }

    /**
     * 报名页面。
     */
    @GetMapping("/front/applyTest")
    public String applyTest( ){
        return "front/index";
    }

    /**
     * 学生考试页面。
     */
    @GetMapping("/front/examine")
    public String examine( ){
        return "front/index";
    }

    /**
     * 学生查看成绩页面。
     */
    @GetMapping("/front/grade")
    public String gradePage( ){
        return "front/index";
    }

    /**
     * 127.0.0.1:81/login ---- get
     */
    @GetMapping("/login")
    public String loginPage(ModelMap modelMap) {
        modelMap.addAttribute("template", "account/login");
        return "indexSimple";
    }

    /**
     * 127.0.0.1:81/logout ---- get
     */
    @GetMapping("/logout")
    public String logout() {
        userService.logout();
        return "redirect:/logout";
    }

    /**
     * 127.0.0.1/register ---- get
     */
    @GetMapping("/register")
    public String registerPage(ModelMap modelMap) {
        modelMap.addAttribute("template", "account/register");
        return "indexSimple";
    }

    /**
     * 127.0.0.1/account/users ---- get
     */
    @GetMapping("/account/users")
    @RequiresRoles(value={"admin","manager"},logical = Logical.OR)
    public String usersPage() {
        return "index";
    }

    /**
     * 127.0.0.1/account/roles ---- get
     */
    @GetMapping("/account/roles")
    @RequiresRoles(value={"admin","manager"},logical = Logical.OR)
    public String rolesPage() {
        return "index";
    }


    /**
     * 127.0.0.1/account/resources ---- get
     */
    @GetMapping("/account/resources")
    @RequiresRoles(value={"admin","manager"},logical = Logical.OR)
    public String resourcesPage() {
        return "index";
    }

    /**
     * 127.0.0.1/account/profile ---- get
     */
    @GetMapping("/account/profile")
    public String profilePage(ModelMap modelMap) {
        return "index";
    }


    /**
     * 暂定前台登录页面
     */
    @GetMapping("/loginn")
    public String loginnPage() {
        return "login";
    }

}
